<?php
/**
 * The Template for displaying all single posts
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */

get_header(); get_template_part('block', 'header-detail-post'); ?>
	<div id="primary" class="site-content">
		<div id="content" role="main">
            <section class="fix">
                <div class="box-utility">
                    <ul class="nav-breadcrumb">
                        <?php  breadcrumb_trail(array('show_title'=>false));

                        ?>
                    </ul>
                    <time class="time"><?php the_date('H:i -  l, d/m/Y');?></time>
                </div>
                <div class="box-news">
                    <h1 class="title"><?php  the_title( );?></h1>
                    <div class="col-left">
                        <h2 class="focus"><?php if(get_field('description')) echo get_field('description'); ?></h2>
                        <img class="thumb" src="<?php echo wp_get_attachment_url( get_post_thumbnail_id(get_the_ID()) );?>" width="300" height="180" alt="<?php  the_title( );?>"/>
                    </div>
                    <div class="col-right">
                        <?php echo get_the_content('Read more');?>
                    </div>
                </div>
                <div class="box-care">
                    <div class="col-left">
                        <div class="relate">
                            <div class="head"><?php echo TITLE_NEW_OTHER;?></div>
                            <?
                            /*lấy 5 tin mới nhất cùng danh mục*/
                            $categories = get_the_category(get_the_ID());
                            $cats_id = array();
                            foreach($categories as $c){
                                $cat_id = $c->term_id;break;
                            }

                            $args = array('category'=>$cat_id, 'exclude'=>get_the_ID(), 'orderby'=> 'post_date','order'=> 'DESC','posts_per_page' => 5, 'post_status' => 'publish');
                            $posts_array = get_posts( $args );
                            ?>
                            <ul class="news-other">
                                <?php foreach($posts_array as $p):?>
                                <li>
                                    <a href="<?php echo get_permalink($p->ID);?>" title="<?php echo $p->post_title;?>"><?php echo $p->post_title;?></a>
                                </li>
                                <?php endforeach;?>
                            </ul>
                        </div>
                    </div>
                    <div class="col-right">
                        <div class="share">
                            <div class="item">
                                <iframe src="//www.facebook.com/plugins/like.php?href=<?php the_permalink(); ?>&amp;width&amp;layout=button_count&amp;action=like&amp;show_faces=false&amp;share=false&amp;height=21&amp;appId=450493091752654" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe>
                            </div>
                            <div class="item">
                                <a href="https://twitter.com/share" class="twitter-share-button" data-dnt="true">Tweet</a>
                                <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
                            </div>
                            <div class="item">
                                <div class="g-plusone" data-size="medium"></div>
                            </div>
                        </div>
                        <div class="tags">
                            <?php
                                $tags = wp_get_post_tags( get_the_ID(), array() );
                                if(!count($tags) == 0){
                                    echo '<span>Tag</span>';
                                    $separation = '';
                                    foreach($tags as $index=>$tag):
                                        if($index > 0)
                                            $separation = ', ';
                                        echo $separation.'<a href="'.get_tag_link($tag->term_id).'" title="'.$tag->name.'">'.$tag->name.'</a>';
                                    endforeach;
                                }
                            ?>
                        </div>
                    </div>
                </div>
                <div class="box-article">
                    <div class="title">Tin tức</div>
                    <div class="data">
                        <?php
                        /*3 tin tức mới ở tất cả tin tức*/
                        $args = array('exclude'=>get_the_ID(), 'orderby'=> 'post_date','order'=> 'DESC','posts_per_page' => 3, 'post_status' => 'publish', 'suppress_filters'=>0,'post_type'=> 'post');
                        $posts_new = get_posts( $args );
                        foreach($posts_new as $p_n2):
                            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $p_n2->ID ), 'single-post-thumbnail' );
                            if(is_array($image) && isset($image[0]))
                                $image = $image[0];
                            else
                                $image = '';
                        ?>
                            <article class="item">
                                <a href="" title="">
                                    <img src="<?php echo $image;?>" width="300" height="180" alt="<?php echo $p_n2->post_title;?>" title="<?php echo $p_n2->post_title;?>"/>
                                </a>
                                <h3>
                                    <a href="<?php echo get_permalink($p_n2->ID);?>" title="<?php echo $p_n2->post_title;?>"><?php echo $p_n2->post_title;?></a>
                                </h3>
                                <time datetime="<?php echo get_the_time('Y-m-d', $p_n2->ID);?>"><?php echo get_the_time('H:i -  l, d/m/Y', $p_n2->ID);?></time>
                                <p>
                                    <?php echo get_field('description', $p_n2->ID);?>
                                </p>
                            </article>
                        <?php endforeach;?>
                    </div>
                </div>
            </section>
		</div><!-- #content -->
	</div><!-- #primary -->
<?php get_footer(); ?>